package com.tron.dobest.java.trontest;


import java.text.ParseException;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Start {

    public static void main(String[] args) throws ParseException {
        String s1 = "123";
        String s2 = "a.123.456";

        Pattern pattern = Pattern.compile(".*\\.{1}123.*");
        Matcher matcher = pattern.matcher(s2);
        System.out.println(matcher.matches());

        System.out.println("============================");

        String orgTree = "ORG_ROOT.685528285748133888.685528433639292928.:五华区公安分局";
        String org = "685528433639292928";

        String parent = getParentOrg(org, orgTree);
        System.out.println(parent);

        String orgPrefix = getOrgPrefix(org, orgTree);
        System.out.println(orgPrefix);

    }

    public static String getParentOrg(String org , String orgTree) {
        String[] split = orgTree.split("\\.");
        for (int i = 0; i < split.length; i++) {
            if (org.equals(split[i])) {
                if (i == 0) {
                    return split[i];
                }else {
                    return split[i - 1];
                }
            }
        }
        return "";
    }

    public static String getOrgPrefix(String org , String orgTree) {
        String substring = orgTree.substring(0, orgTree.indexOf(org));
        return substring;
    }

    public String getBaseCode(String string) {
        return Base64.getEncoder().encodeToString("test".getBytes());
    }

    public void testLambda() {
        List<String> strings = Arrays.asList("a", "b", "b");
        List<String> list = strings.stream().filter(e -> e.equals("b")).collect(Collectors.toList());
        System.out.println(list);
    }

}
